import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonaNewguidePage(Base):
    """
    新手引导
    """

    # TODO:

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.new_home_btn = (By.XPATH, Personal.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.new_back_btn = (By.XPATH, Personal.RESOURCE_ID.format('ivBack'))

        # 新手引导模式标题
        self.new_page_title_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_title"))

        # 下方各个应用的名称,使用时需传入对应的分类名称
        # self.new_list_category_title_text = (By.XPATH, Page.TEXT.format(""))
        self.new_list_category_title_text = (By.XPATH, Personal.new_guide_list_category_name_text.format(""))

        # 下方各个分类的封面, 使用时需传入对应的分类名称
        self.new_list_category_cover_img = (By.XPATH, Personal.new_guide_list_category_cover_img.format(""))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.new_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.new_home_btn)

    def get_page_title(self):
        """
        获取新手引导页面标题

        :return: 获取元素
        """
        return self.find_element_o(self.new_page_title_text)

    def get_list_category_title(self, category_name):
        """
        获取指定分类的名称

        :return:
        """
        # self.new_list_category_title_text = (By.XPATH, Page.TEXT.format(category_name))
        self.new_list_category_title_text = (By.XPATH, Personal.new_guide_list_category_name_text.format(category_name))
        return self.find_element_o(self.new_list_category_title_text)

    def get_list_category_cover(self, category_name):
        """
        获取指定分类的封面

        :param category_name:分类名称
        :return:
        """
        # self.new_list_category_cover_img = (By.XPATH, Page.TEXT.format(category_name))
        self.new_list_category_cover_img = (By.XPATH, Personal.new_guide_list_category_cover_img.format(category_name))
        return self.find_element_o(self.new_list_category_cover_img)

    def click_list_category_name(self, category_name):
        """
        点击新手引导页面应用名称

        :return:None
        """
        # self.new_list_category_title_text = (By.XPATH, Page.TEXT.format(category_name))
        self.new_list_category_title_text = (By.XPATH, Personal.new_guide_list_category_name_text.format(category_name))
        self.click_element(self.new_list_category_title_text)

    def is_display_personal_new(self):
        """
        是否存在新手引导界面

        :return: bool
        """
        return self.is_display(self.new_page_title_text)
